package xyz.scootaloo.oj.offer

import org.junit.Test
import xyz.scootaloo.oj.ds.ListNode
import java.sql.Date
import java.util.*

/**
 * @author flutterdash@qq.com
 * @since 2021/4/10 15:25
 */
class P22 {

    /**
     *
     *    1 -> 2 -> 3 -> 4 -> 5
     * s--^
     * f-------^
     * s-------^
     * f-----------------^
     * s------------^
     * f----------------------x----null
     */
    fun getKthFromEnd(head: ListNode?, k: Int): ListNode? {
        if (head == null) return null
        val deque = LinkedList<ListNode>()
        var pointer = head
        while (pointer != null) {
            deque.addLast(pointer)
            pointer = pointer.next
        }
        if (k > deque.size) return null
        val listIterator = deque.listIterator(k)
        return null
    }

    @Test
    fun test0() {
        val date = Date.valueOf("2021-4-10")
        println(date)
    }

}
